Shared AutoReport class for Temperature, Cardreader#20913
Shared AutoReport class for Temperature, Cardreader#20913thinkyhead merged 2 commits intoMarlinFirmware:bugfix-2.0.xfrom
Conversation
58feb92 to
3909cea
Compare
|
This one has broken Temp reporting for me. I rolled back to the commit before this one, and was able to get temps in Octoprint again. |
)" This reverts commit 9d0e64a.
)" This reverts commit 9d0e64a.
| // SD Auto Reporting | ||
| // | ||
| #if HAS_MULTI_SERIAL | ||
| static serial_index_t auto_report_port; |
There was a problem hiding this comment.
This is wrong as a static variable is not a constexpr so it can't be used as a template parameter.
| const millis_t ms = millis(); | ||
| if (ELAPSED(ms, next_report_ms)) { | ||
| next_report_ms = ms + SEC_TO_MS(report_interval); | ||
| PORT_REDIRECT(AR_PORT_INDEX); |
There was a problem hiding this comment.
Beware, since the serial hooking code, PORT_REDIRECT expect a mask, not an index, you should use PORT_REDIRECT(SERIAL_MASK(AR_PORT_INDEX)) here instead.
There is no need for template parameter here, the mask is a runtime variable, it can be changed anytime!
| #endif | ||
| class AutoReportSD : public AutoReporter<auto_report_port> { void auto_report(); }; | ||
| static AutoReportSD auto_reporter; | ||
| #endif |
There was a problem hiding this comment.
I think, there is no need for a template AutoReporter here, just set the serial_index_t as a member of the class since it's only used for PORT_REDIRECT which is a runtime check, and you can also remove the #if HAS_MULTI_SERIAL condition here so it'll be simpler.
| auto_report_temp_interval = v; | ||
| next_temp_report_ms = millis() + 1000UL * v; | ||
| } | ||
| class AutoReportTemp : public AutoReporter<SERIAL_ALL> { void auto_report(); }; |
There was a problem hiding this comment.
auto_report is not virtual so this is never called when manipulating the base class.
There was a problem hiding this comment.
If you want to avoid the cost of a virtual table (since the instance is known at compile time), you can use CRTP here:
template <class Child>
struct AutoReporter
{
[...]
inline void auto_report() { static_cast<Child*>(this)->report(); } // Call the child's version. Does not need to be called auto_report
[...]
};
// You need a default implementation that does not report.
struct NoAutoReport : public AutoReporter<NoAutoReport> { void report() {} };
// Then subclass like this:
struct AutoReportTemp : public AutoReporter<AutoReportTemp> { void report() { ... } };
But this means you'll have to typedef the actual class to use since the type will change on each platform:
// In some common header, select the type to use based on compile time information:
#ifdef HAS_MULTI_SERIAL
typedef AutoReportMulti AutoReport;
#else if ...
typedef NoAutoReport AutoReport;
[...]
#endif
// Ok, let's declare the reporter instance
extern AutoReport auto_reporter;
|
@lightmaster : Can you replace the line 33 from autoreport.h from: to It should fix it. |
Confirmed that this change fixes temperature auto-reporting for me. (BTT SKR 1.4 Turbo, if it matters.) |
Worked for me, ender 3 pro with skr mini E3 |
|
@Guilouz Yes, it's known. It'll be fixed soon. |
|
Thanks! |
|
But it's failed when I try to disable #define SDSUPPORT Working with stable build 2.7.0.2 not with bugfix. |
|
Seems like it related #20846, that's another bug. Can you open a new issue ? |
|
Yes I can. |
…mware#20913)"" This reverts commit f301646.
…mware#20913)"" This reverts commit ae0eeb2.


SEC_TO_MSwhere contextually-appropriate.